<template>
	<view>
		<view class="address-section">
			<!-- <mpvue-city-picker :themeColor="themeColor" ref="mpvueCityPicker"
				:pickerValueDefault="cityPickerValueDefault" @onConfirm="onConfirm"></mpvue-city-picker> -->

			<view class="row b-b" v-if="wechat">
				<image :src="wechat" mode=""></image>
			</view>

			<view class="row b-b" v-else>
				<robby-image-upload src="/static/img/login/add.png" :width="width" :height="height"
					:lineheight="lineheight" :borderRadius="borderRadius"></robby-image-upload>

			</view>

		</view>
	</view>
</template>

<script>
	import robbyImageUpload from '@/components/robby-image-upload/robby-image-upload3.vue';
	import {
		mapState,
		mapMutations
	} from 'vuex';

	export default {
		components: {
			robbyImageUpload
		},
		data() {
			return {
				title: '',
				id: 0,
				width: '450upx',
				height: '450upx',
				lineheight: '450upx',
				borderRadius: '0',

				wechat: ''
			}
		},
		onLoad(options) {
			//判断是否登录
			let result = this.$api.isLogin();
			if (result === false) {
				return false;
			}

			if (options.wechat != 'null' && options.wechat != '') {
				this.wechat = options.wechat
			}

			uni.$on('changeWechat', (options) => {
				this.wechat = options.path;
				this.wechatImg(options.path)
			})
		},
		computed: {
			...mapState(['hasLogin']),
		},
		methods: {
			...mapMutations(['login', 'logout']),

			async wechatImg(path) {
				let token = uni.getStorageSync('token');
				let res = await this.$myRequest({
					url: '/changeWechat',
					data: {
						token: token,
						path: path
					},
					methods: 'post'
				})

				uni.$emit('changeUser')
				// this.$api.msg(res.data.msg);
				setTimeout(() => {
					uni.navigateTo({
						url: '/pages/user/userData'
					})
				}, 1000)
			},
		},
	}
</script>

<style lang="scss">
	page {
		background: #f1f1f1;
		// padding-top: 16upx;
	}

	.row {
		display: flex;
		// align-items: center;
		justify-content: center;
		position: relative;
		padding: 20rpx;
		height: 100%;
		background: #fff;
		border-bottom: 1rpx solid #e5e5e5;

		// margin-top: 10rpx;
		.tit {
			flex-shrink: 0;
			width: 170upx;
			font-size: 28upx;
			color: #303133;
		}

		.input {
			flex: 1;
			font-size: 28upx;
			color: #303133;
		}

		.icon-shouhuodizhi {
			font-size: 36upx;
			color: #909399;
		}
	}

	.default-row {
		margin-top: 20upx;

		.tit {
			flex: 1;
		}

		switch {
			transform: translateX(16upx) scale(.9);
		}
	}

	.add-btn {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 690upx;
		height: 80upx;
		margin: 60upx auto;
		font-size: 32upx;
		letter-spacing: 4upx;
		color: #fff;
		background-color: #29ad97;
		border-radius: 50upx;
		box-shadow: 1px 2px 5px #dadada;
	}
</style>
